<template>
  <el-card class="header-card">
    <div class="card-wrap">
      <el-page-header content="审批详情" @back="goBack" />
      <div v-if="isApproval && nodeId !='ACT_010' || (nodeId =='ACT_010' && projectInfo.stageStatus == 5 || projectInfo.stageStatus == 6)">
        <el-button @click="goBack">取消</el-button>
        <el-button
          type="primary"
          :loading="model.saveLoading"
          @click="handleSave"
          >保存</el-button
        >
        <template v-if="!model.isNoReject">
          <el-button
            type="primary"
            :loading="model.saveLoading"
            @click="handleReject"
            >驳回</el-button>
        </template>

        <el-button
          type="primary"
          :loading="model.saveLoading"
          @click="handleFlowNotify" v-if="modeType!='toread'&&modeType!='read'"
          >知会</el-button
        >
        <el-button
          type="primary"
          :loading="model.saveLoading"
          @click="handleSubmit"
          >提交</el-button
        >
      </div>

      <template v-else>
          <div>
            <el-button
              type="primary"
              @click="toEdit" v-if="isApproval && nodeId == 'ACT_010'"
              >重新编辑</el-button
            >
            <el-button
              type="primary"
              :loading="model.saveLoading"
              @click="handleFlowNotify" v-if="modeType!='toread'&&modeType!='read'"
              >知会</el-button
            >
            <el-button
              type="primary"
              :loading="model.saveLoading"
              @click="handleRecall" v-if='canRecall == 1'
              >撤回</el-button
            >
          </div>
      </template>
    </div>
  </el-card>
  <br />

  <el-card class="base-card">
    <template #header>
      <div class="card-box-header">
        <span>项目基本信息</span>
        <div v-if="show1" @click="show1 = !show1" class="header-btn">
          收起
          <i class="el-icon-arrow-down"></i>
        </div>
        <div v-else @click="show1 = !show1" class="header-btn">
          展开
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
    </template>
    <div v-show="show1">
      <BasicsInfo :projectInfo="projectInfo"/>
    </div>
  </el-card>
  <br />

  <!-- 可行性研究 -->
  <template v-if='projectInfo.stageStatus == 1'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>可行性研究</span>
          <div v-if="show8" @click="show8 = !show8" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show8 = !show8" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show8">
        <Feasibility :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 实施信息 -->
  <template v-else-if='projectInfo.stageStatus == 3'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>项目实施计划</span>
          <div v-if="show8" @click="show8 = !show8" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show8 = !show8" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show8">
        <Implementation :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 验收 -->
  <template v-else-if='projectInfo.stageStatus == 4'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>项目验收</span>
          <div v-if="show8" @click="show8 = !show8" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show8 = !show8" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show8">
        <Check :projectInfo="projectInfo"/>
        <Tab7/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 后评价 -->
  <template v-else-if='projectInfo.stageStatus == 5 || projectInfo.stageStatus == 6'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span v-if='projectInfo.stageStatus == 6'>关闭项目</span>
          <span v-else>后评价</span>
          <div v-if="show8" @click="show8 = !show8" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show8 = !show8" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show8">
        <Evaluate :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 终止，变更 -->
  <template v-else-if='projectInfo.stageStatus == 20 || projectInfo.stageStatus == 21 || projectInfo.stageStatus == 22'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span v-if='projectInfo.stageStatus == 22'>终止申请信息</span>
          <span v-else>变更申请信息</span>
          <div v-if="show7" @click="show7 = !show7" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show7 = !show7" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show7">
        <ChangeInfo :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 备案 -->
  <template v-else-if='projectInfo.stageStatus == 0 && projectInfo.isFilings == 2'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>项目备案</span>
          <div v-if="show7" @click="show7 = !show7" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show7 = !show7" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show7">
        <FilingsInfo :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 项目工时 -->
  <template v-else-if='projectInfo.stageStatus == 60'>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>项目工时</span>
          <div v-if="show7" @click="show7 = !show7" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show7 = !show7" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show7">
        <ManHour :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 建档,立项 -->
  <template v-else>
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>评审内容</span>
          <div v-if="show2" @click="show2 = !show2" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show2 = !show2" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show2">
        <ReviewInfo :projectInfo="projectInfo"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 建档,关闭项目,不需要专家评审意见 -->
  <template v-if='projectInfo.stageStatus != 0 && projectInfo.stageStatus != 6 && projectInfo.stageStatus != 60'>
    <el-card class="expert-card">
      <template #header>
        <div class="card-box-header">
          <el-tooltip
            class="box-item"
            effect="dark"
            content="如涉及专家评审，科创管理人员可进入【专家评审】模块发起专家评审，评审信息将自动同步。"
            placement="top-start"
          >
           <span>专家评审意见<i class="el-icon-question" color="#f89c34" size="24"></i></span>
          </el-tooltip>
          <div v-if="show3" @click="show3 = !show3" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show3 = !show3" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show3">
        <ExperReviewtList :projectInfo="projectInfo"/>
        <BuildApproval :projectInfo="projectInfo" class="mg-top"/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 待处理 -->
  <template v-if="isApproval">
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>待处理</span>
          <div v-if="show4" @click="show4 = !show4" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show4 = !show4" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show4">
        <template v-if='nodeId == "ACT_010"'>
          <!-- 后评价驳回到填报人编辑信息在当前页面，其他流程跳到对应项目详情页面 -->
          <EditEvaluate ref="pendRef" :projectInfo="projectInfo" v-if='projectInfo.stageStatus == 5 || projectInfo.stageStatus == 6' />
          <el-link :underline="false" @click="toEdit" class="to-edit" v-else>重新编辑</el-link>
        </template>
        <PendingInfo :projectInfo="projectInfo" ref="pendRef" v-else/>
      </div>
    </el-card>
    <br />
  </template>

  <!-- 流程状态 -->
  <el-card>
    <template #header>
      <div class="card-box-header">
        <span> 流程状态</span>
        <div v-if="show5" @click="show5 = !show5" class="header-btn">
          收起
          <i class="el-icon-arrow-down"></i>
        </div>
        <div v-else @click="show5 = !show5" class="header-btn">
          展开
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
    </template>
    <div v-if="currentStep">
      <el-collapse-transition>
        <!-- <status-info
          :currentStep="currentStep"
          :steps="steps"
          :isSkip="isSkipLx"
        /> -->
        <img :src="currentStep" />
      </el-collapse-transition>
    </div>
  </el-card>
  <br />

  <!-- 流转记录 -->
  <el-card>
    <template #header>
      <div class="card-box-header">
        <span> 流转记录</span>
        <div v-if="show6" @click="show6 = !show6" class="header-btn">
          收起
          <i class="el-icon-arrow-down"></i>
        </div>
        <div v-else @click="show6 = !show6" class="header-btn">
          展开
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
    </template>
    <div v-show="show6">
      <el-collapse-transition>
        <approval-info :activities="approveRecord" />
      </el-collapse-transition>
    </div>
  </el-card>

  <approveDialog
    v-if="approveDialogVisiable"
    :nodeId="nodeId"
    :flowType="flowType"
    :approveRecord="approveRecord"
    @cancel="cancel"
    @sure="sureSubmit"
  ></approveDialog>

  <rejectDialog
    v-if="rejectDialogVisiable"
    :nodeId="nodeId"
    :isSkip="isSkipLx"
    :flowType="flowType"
    @cancel="cancel"
    @sure="sureRejectSubmit"
  ></rejectDialog>

  <addUser @sure="submitFlowNotify" @cancel="addUserDialogVisiable = false" title="请选择知会人员" v-if="addUserDialogVisiable"></addUser>
</template>

<script lang="ts" setup>
import { ref, reactive } from "vue";
import { useRouter, useRoute } from "vue-router";
import BasicsInfo from "../BasicsInfo.vue";
import addUser from "../addUser.vue";
import ExperReviewtList from "../ExperReviewtList.vue";
import BuildApproval from "../BuildApproval.vue";
import ChangeInfo from "../ChangeInfo.vue";
import Implementation from "../Implementation.vue";
import Check from "../Check.vue";
import Evaluate from "../Evaluate.vue";
import Feasibility from "./Feasibility.vue";
import PendingInfo from "./PendingInfo.vue";
import ReviewInfo from "./ReviewInfo.vue";
import FilingsInfo from "./FilingsInfo.vue";
import EditEvaluate from "./EditEvaluate.vue";
import ManHour from "./ManHour.vue";
import approveDialog from "/@/components/approveDialog/index.vue";
import rejectDialog from "/@/components/rejectDialog/index.vue";
import StatusInfo from "/@/components/StatusInfo/index.vue";
import ApprovalInfo from "/@/components/ApprovalInfo/index.vue";
import Tab7 from "../../../../project/detail/components/descTabs/tab7.vue";
import { flowStatusObj } from "/@/components/StatusInfo/type";
import { flowTypeObj } from "/@/components/approveDialog/type";
import { storageLocal } from "/@/utils/storage";
import {stageToPath}  from  "/@/utils/globalConstant";
import {
  getProjectInfo,
  flowSubmit,
  flowReject,
  getApproveHandlerId,
  getTaskId,
  submitStage
} from "/@/api/project";
  import {getApproveImg} from "/@/api/project";
import {
  saveStorageFormData,
  getStorageFormData,
  postRecall,
  flowNotify
} from "/@/api/approval";
import { cloneDeep } from "lodash-es";
import NotifMessage from "/@/utils/message/notification";
const props = defineProps({
  canRecall: {
    type: String,
    default:""
  },

  approveRecord:{
    type: Array,
    default:() => []
  }
});
const router = useRouter();
const route = useRoute();
const pendRef = ref<HTMLFormElement | null>(null) as any;
let show1 = ref<boolean>(true);
let show2 = ref<boolean>(true);
let show3 = ref<boolean>(true);
let show4 = ref<boolean>(true);
let show5 = ref<boolean>(true);
let show6 = ref<boolean>(true);
let show7 = ref<boolean>(true);
let show8 = ref<boolean>(true);
let addUserDialogVisiable = ref<boolean>(false);    //人员选择器弹窗
let approveDialogVisiable = ref<boolean>(false); // 点击提交弹窗，选择下一步审批人
let rejectDialogVisiable = ref<boolean>(false); // 点击驳回弹窗，选择下一步审批人
const nodeId = route.query.nodeId ? route.query.nodeId : "ACT_010";
const modeType = route.query.mode;
const isApproval = route.query.mode === "approval" ? true : false;
const isSkipLx = route.query.isSkipLx;
const flowType = route.query.flowType;
const projectManageId = route.query.projectManageId;
const billName = route.query.billName;
const busCategoryName = route.query.busCategoryName;
const busCategoryCode = route.query.busCategoryCode;
const instanceId = route.query.instanceId;
const currentStep = ref(null);
const steps = ref([]);
const projectInfo = ref({});
const option = ref([]);
const userInfo = storageLocal.getItem("rdms-info");
const model = reactive({
  approveHandlerId: null,
  saveLoading: false,
  isNoReject: false,
  dialogType: "approval",
  stageCodeList:["20","21","22","32","33","60"],//变更审批和终止,月度和年度经费，工时填报
  billNameStage:[
    {name:"项目建档-审批流程",value:0},
    {name:"可行性研究-审批流程",value:1},
    {name:"项目立项-审批流程",value:2},
    {name:"项目实施-审批流程",value:3},
    {name:"项目验收-审批流程",value:4},
    {name:"后评价项目-审批流程",value:5},
    {name:"一般变更-审批流程",value:20},
    {name:"重大变更-审批流程",value:21},
    {name:"项目终止-审批流程",value:22},
    {name:"关闭项目-审批流程",value:6}
  ]
});

//审批流程
const flowPassData = reactive({
  formBaseInfo: {
    id: route.query.id,
    acceptUsers: null
  },
  flowFormData: {
    approvalComments: "",
    approvalResult: "",
    businessId: route.query.id,
    flowId: route.query.flowId,
    flowTypeCode: flowType,
    instanceId: instanceId,
    nodeId: route.query.nodeId,
    remarks: "",
    saveState: "1"
  },
  formSubMap: {
    stageStatus: "0",
    flowType: flowType,
    nodeId: route.query.nodeId,
    procInstId: instanceId,
    taskId: "",
    opinion: "",
    assignee: null,
    isChargehand: "1", //1：向下提交到下一步：0：回退到某一步
    specialReject: "0"
  },
  tmpStorage: {
    nodeId: route.query.nodeId,
    flowId: route.query.flowId,
    taskId: "",
    handlerId: null,
    valueJson: ""
  }
});

const flowRejectData = reactive({
  formRejectMap: {
    procInstId: instanceId,
    nodeId: route.query.nodeId,
    taskId: "",
    opinion: ""
  }
});

// 点击提交，校验通过后，弹窗：选择下一节点处理人
const handleSubmit = async type => {
  model.dialogType = "approval";
  const isValid = await pendRef.value.validate()
  if (!isValid) {
    NotifMessage.warning("请补充必填信息后，再次操作！");
    return
  }
  approveDialogVisiable.value = true;
};

//后评价审批时更新项目状态
const submitProStage = async (params) => {
  try {
    const { code } = await submitStage(projectManageId);
    if (code === 200) {
      passProcess(params)
    }
  } catch (err) {
    return true;
  }
};

// 点击弹窗的确定后、提交，单据往下流转
const sureSubmit = async params => {
  approveDialogVisiable.value = false;
  model.saveLoading = true;
  const pendFormData = pendRef.value.model.formData;
  flowPassData.flowFormData.approvalComments = pendFormData.remark;
  flowPassData.flowFormData.approvalResult = pendFormData.isApprove || "1"; //同意：1，不同意：0
  flowPassData.flowFormData.remarks = pendFormData.remark;
  option.value = [
    { name: "审批意见", content: `${pendFormData.isApprove === "1" ? "同意" : "不同意"}`, type: "textarea" },
    { name: "备注", content: `${pendFormData.remark}`, type: "textarea" },
  ];
  if(projectInfo.value.stageStatus == "5" || projectInfo.value.stageStatus == "6"){//后评价，关闭项目
    option.value = [
      { name: "附件", content:pendFormData.evaluationAttachment ? JSON.parse(pendFormData.evaluationAttachment) : '' , type: "file" },
    ];
    submitProStage(params)
  }
  else{
    passProcess(params);
  }
};

// 流程审批
const passProcess = async params => {
  flowPassData.tmpStorage.handlerId = userInfo?.userId;
  flowPassData.tmpStorage.taskId = projectInfo.value.taskId;
  flowPassData.formSubMap.taskId = projectInfo.value.taskId;
  flowPassData.formSubMap.stageStatus = projectInfo.value.stageStatus;
  if (params?.feasibilityreList && params.feasibilityreList.length) {
    //是否支持上传附件
    //会签记录
    const file = JSON.stringify(params.feasibilityreList);
    option.value.push({name: "会签记录", content: `${file}`, type: "file"})
  }
  if (!params.isSingle) {
    //会签，多人审批
    if (params?.handlederId && params.handlederId.length) {
      if(Array.isArray(params.handlederId)) {
        const idList = params.handlederId.map(item => {
          return item.id;
        });
        flowPassData.formBaseInfo.acceptUsers = idList.join() || userInfo?.userId;
        flowPassData.formSubMap.assignee = idList.join() || userInfo?.userId;
      } else {
        flowPassData.formBaseInfo.acceptUsers = params?.handlederId?.id || userInfo?.userId;
        flowPassData.formSubMap.assignee = params?.handlederId?.id || userInfo?.userId;
      }
    } else {
      flowPassData.formBaseInfo.acceptUsers = params?.handlederId?.id || userInfo?.userId;
      flowPassData.formSubMap.assignee = params?.handlederId?.id || userInfo?.userId;
    }
  } else {
    flowPassData.formBaseInfo.acceptUsers = params?.handlederId?.id || userInfo?.userId;
    flowPassData.formSubMap.assignee = params?.handlederId?.id || userInfo?.userId;
  }

  if (params.nextJumpTo && params.nextJumpTo.length) {
    //当前节点可以选择多下级审批节点
    flowPassData.formSubMap.isChargehand = params.nextJumpObj.isChargehand;
  } else {
    if (model.dialogType === "reject") {
      //通过当前流程，流程退回指定节点或者非正常流程
      flowPassData.formSubMap.isChargehand = params.backJumpObj.isChargehand;
      flowPassData.formBaseInfo.acceptUsers = model.approveHandlerId; //回退节点的处理人
      flowPassData.formSubMap.assignee = model.approveHandlerId;
    } else {
      //通过当前流程，流程流转到后续流程（(正常流程)）
      flowPassData.formSubMap.isChargehand = "1";
    }
  }
  model.saveLoading = true;
  flowPassData.tmpStorage.valueJson = JSON.stringify(flowPassData.formSubMap);
  flowPassData.formSubMap.opinion = JSON.stringify(option.value)
  const { code, message } = await flowSubmit(flowPassData);
  if (code === 200) {
    NotifMessage.success(message);
    goBack();
  } else {
    NotifMessage.error(message);
  }
};

//点击驳回(可选驳回到第一个节点，或者上一节点以及指定节点)
const handleReject = async () => {
  model.dialogType = "reject";
  rejectDialogVisiable.value = true;
};

//确定驳回(或者驳回指点节点)
const sureRejectSubmit = async params => {
  model.saveLoading = true;
  if (params.backJumpObj.isRejectBack) {
    //是否真驳回到上一步
    const option = [{ name: "驳回意见", content: `${params.remark}`, params: "textarea" }];
    flowRejectData.formRejectMap.opinion = JSON.stringify(option);
    flowRejectData.formRejectMap.taskId = projectInfo.value.taskId;
    const { code, message } = await flowReject(flowRejectData);
    if (code === 200) {
      NotifMessage.success(message);
      goBack();
    } else {
      NotifMessage.error(message);
    }
  } else {
    //驳回到第一步或者指定节点
    if (flowType) {
      //流程退回指定节点,获取节点的处理人
      const backNodeId = params.backJumpObj.backJumpToId; //驳回到的指定节点
      backNodeId && getApproveUserId(backNodeId, params);
    }
  }
};

//流程撤回
const handleRecall = async () => {
  try {
    const preNodeId = route.query.preNodeId ? route.query.preNodeId : "ACT_010";
    const params = {instanceId,nodeId:preNodeId};
    const { code, message } = await postRecall(params);
    if (code === 200) {
      NotifMessage.success(message);
      goBack();
    } else {
      message && NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

//选择知会人员
const handleFlowNotify = async parmas => {
  addUserDialogVisiable.value = true;
};

//确定知会
const submitFlowNotify = async parmas => {
  const notifys = [];
  const id = parmas?.userInfo?.id;
  notifys.push(id);
  let taskId = projectInfo.value.taskId;
  if(!taskId){
      const len = props.approveRecord.length
      taskId = len && props.approveRecord[len-1]?.taskId;
  }
  let params = {
    assignee: userInfo?.userId,
    instanceId: instanceId,
    taskId: taskId,
    notifys: notifys
  };
  try {
    const { code, message } = await flowNotify(params);
    if (code === 200) {
      addUserDialogVisiable.value = false;
      NotifMessage.success(message);
      goBack();
    } else {
      NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

// 保存审批数据
const handleSave = async () => {
  const isValid = await pendRef.value.validate()
  if (isValid) {
    const pendFormData = pendRef.value.model.formData;
    let params = {
      nodeId: nodeId,
      taskId: projectInfo.value.taskId,
      flowId:route.query.flowId,
      handlerId: userInfo ? userInfo?.userId : "",
      userId: userInfo ? userInfo?.userId : "",
      handlerName: userInfo ? userInfo?.name : "",
      valueJson: JSON.stringify(pendFormData)
    };
    try {
      const { code, message } = await saveStorageFormData(params);
      if (code === 200) {
        goBack();
        NotifMessage.success("保存成功");
      } else {
        NotifMessage.error(message);
      }
    } catch (err) {
      console.log(err);
    }
  }else{
    NotifMessage.warning("请补充必填信息后，再次操作！");
    return
  }
};

// 获取保存的数据
const getStorageFormDataInfo = async () => {
  let params = {
    nodeId: nodeId,
    taskId: projectInfo.value.taskId,
    flowId:route.query.flowId,
    handlerId: userInfo ? userInfo?.userId : ""
  };
  const { code, data } = await getStorageFormData(params);
  if (code === 200) {
    if (data?.valueJson) {
      const saveData = JSON.parse(data.valueJson);
      projectInfo.value.isApprove = saveData.isApprove;
      projectInfo.value.remark = saveData.remark;
      projectInfo.value.evaluationReport = saveData.evaluationReport;
    }
  }
};

//获取某一节点的处理人
const getApproveUserId = async (nodeId, params) => {
  model.saveLoading = true;
  const { code, data } =
    instanceId && (await getApproveHandlerId(instanceId, nodeId));
  if (code === 200) {
    model.approveHandlerId = data[0];
    flowPassData.flowFormData.remarks = params.remark;
    option.value = [
      { name: "备注", content: `${params.remark}`, type: "textarea" },
    ];
    passProcess(params);
  } else {
    NotifMessage.error("获取处理人失败");
  }
};

//查询项目详情
const getProjectFormInfo = async () => {
  const { code, data } = projectManageId && await getProjectInfo({id:projectManageId });
  if (code === 200) {
    projectInfo.value = cloneDeep(data);
    projectInfo.value.billName = billName;
    projectInfo.value.busCategoryName = busCategoryName;
    projectInfo.value.projectManageId = projectManageId;
    projectInfo.value.flowType = flowType;
    if(model.stageCodeList.includes(String(busCategoryCode))){//变更审批和终止,月度和年度经费重新赋值
      projectInfo.value.stageStatus = busCategoryCode;
    }
    if(billName){
      model.billNameStage.forEach(item => {//根据单据名称区分项目阶段
        if(billName.includes(item.name)){
          projectInfo.value.stageStatus = item.value
        }
      })
    }
    model.isNoReject = flowTypeObj[flowType][nodeId].isNoReject; //是否展示驳回按钮
    getApprovalTaskId();
  }
};

//查询流程taskId
const getApprovalTaskId = async () => {
  if (instanceId) {
    const { code, data } = await getTaskId({instanceId:instanceId});
    if (code === 200) {
      projectInfo.value.taskId = data.taskId;
      if(projectInfo.value.taskId){
        getStorageFormDataInfo()
      }
    }
  }
};

//获取流程转态
const getStep = async () => {
  const instanceId = route.query.instanceId;
    const { code, data } = await getApproveImg(instanceId);
    if (code === 200) {
      currentStep.value = data;
    }
};

const toEdit = async () => {
  let pathUrl = stageToPath[projectInfo.value.stageStatus];
  let mode = "edit";
  let id = projectManageId;
  if(projectInfo.value.isFilings == "2"){//备案项目
    pathUrl = "/project/filings/detail";
  }
  if(projectInfo.value.stageStatus == "60"){//项目工时
    id = route.query.id;
  }
  let pathQuery = {
    flowType:flowType,
    id: id,
    projectId:projectInfo.value.projectManageId,
    taskId:projectInfo.value.taskId,
    flowId: route.query.flowId,
    instanceId: instanceId,
    nodeId: nodeId,
    source:"back",
    mode:mode
  };
  router.push({
    path: pathUrl,
    query: pathQuery
  });
}
const goBack = (): void => {
  router.back()
};
const cancel = async () => {
  rejectDialogVisiable.value = false;
  approveDialogVisiable.value = false;
  model.saveLoading = false;
};
getProjectFormInfo();
getStep();
</script>

<style lang="scss" scoped>
.empt-content {
  height: calc(100vh - 200px);
  width: 100%;
}

.card-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .header-btn {
    font-size: 14px;
    cursor: pointer;
  }
}

.sub-title{
  font-size:14px;
  font-weight: bold;
}
.mg-top{
  margin-top: 20px;
}
.box-item{
  cursor: pointer;
  .el-icon-question:before{
    color:#f89c34;
    margin-left:4px;
  }
}
.to-edit{
  color:#f9b05d;
  font-size: 16px;
}
.expert-card{
  :deep .el-card__body{
    padding-top:0 !important
  }
}
</style>
